﻿function Menu(Arguments)
    {
    //Global variables.
    var menu=null;
 
 
 
   
    var Messenger_subMenu=null;
    var MessengerArgs = {
            Base: Arguments.Base,
            subleft:Arguments.subleft,
            ClickEventListener: OnClick2
        };
     
    Messenger_subMenu=new SubMenu(MessengerArgs);
    Messenger_subMenu.AddItem('Images/online.png',10, 'Available', false, 'Available');
    Messenger_subMenu.AddItem('Images/away.png',10, 'Invisible', false, 'Invisible');
    Messenger_subMenu.AddItem('Images/idle.png',10, 'Busy', false, 'Busy');
    Messenger_subMenu.AddItem('Images/offline.png',10, 'Offline', false, 'Offline');
   
    
    
    
  	var Base = Arguments.Base ? Arguments.Base : document.documentElement;
	var Left = Arguments.left;
	var Width = 135;            //set the width of the context menu
   	var ID=Arguments.ID;
   	var HoverFontColor = Arguments.HoverFontColor ? Arguments.HoverFontColor : '#666666';
	var HoverBackgroundColor = Arguments.HoverBackgroundColor ? Arguments.HoverBackgroundColor : '#666666';
	var HoverBorderColor = Arguments.HoverBorderColor ? Arguments.HoverBorderColor : 'orange';
	var ClickEventListener = Arguments.ClickEventListener ? Arguments.ClickEventListener : function(){ return false; };
	
    var MenuDiv = document.createElement('div');
    var MenuTable = document.createElement('table');
 
    var Index = 0;
    var EventHandlers = new Array();
	

	//Style Context Menu div.                 //the entire context menu
    MenuDiv.id = ID; 
    MenuDiv.style.position = 'absolute';
    MenuDiv.style.verticalAlign = 'top';
    MenuDiv.style.textAlign = 'left';
	MenuDiv.style.visibility = 'hidden';
	MenuDiv.style.width = (Width + 11) + 'px';
	MenuDiv.style.height=80+'px';
	//MenuDiv.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=100)';



	
	//Styles Context Menu table.
	MenuTable.id = 'MenuTable'; 
	MenuTable.style.width = (Width + 10) + 'px';
	MenuTable.style.backgroundColor = '#507cd1'; 
	MenuTable.style.border='2px groove gray';
	MenuTable.style.marginTop = '3px';
	MenuTable.style.marginBottom = '3px';
	MenuTable.cellPadding = 0;
	MenuTable.cellSpacing = 0;
	
	//Append Context Menu table into Context Menu div.
	MenuDiv.appendChild(MenuTable);
	
	//Public method for adding Context Menu Items.
	this.AddItem = function(imgSrc,imgSize, itemText, isDisabled, menuCommand)
	{	    
		var Tr = MenuTable.insertRow(Index++);   //table row names
	    Tr.id=menuCommand;  //**********
	    Tr.style.fontFamily = 'Microsoft Sans Serif';
	    Tr.style.fontSize = 'XX-Small';           //set Font size
	    Tr.style.fontWeight = 'normal';
	    Tr.style.backgroundColor = '#507cd1';
	    Tr.style.cursor = 'default';
		
	    var TdLeft = Tr.insertCell(0);  //table row image
	    TdLeft.style.width = 110 + 'px';
	    TdLeft.style.height = 15 + 'px';
	    TdLeft.style.textAlign = 'left';
	    //TdLeft.style.verticalAlign = 'left';
	    TdLeft.style.fontFamily = 'Microsoft Sans Serif';
	    TdLeft.style.fontSize = 'XX-Small';
	    TdLeft.innerHTML = '&nbsp;&nbsp;&nbsp;'+itemText;        //? itemText : '&nbsp;';
	    TdLeft.style.color='white';
	
	    var TdRight = Tr.insertCell(1);     //text
	    TdRight.style.width = 15 + 'px';
	    TdRight.style.height = 15 + 'px';
	    TdRight.style.textAlign = 'center';
	 	 	
		if(imgSrc!=' ')
		{
	        var Img = new Image();	 
	        Img.id = 'Img';    
	        Img.src = imgSrc;
	        Img.style.width = imgSize + 'px';	 //set image width here
	        Img.style.height = imgSize + 'px';	 //set image height here
	        Img.disabled = isDisabled; 
			
	        TdRight.appendChild(Img);	
	    }
	    else
	        TdRight.innerHTML = '&nbsp;';
		
	    //Register events.	    
	    if(!isDisabled)
		{	        
			WireUpEventHandler(Tr, 'click', function(){ ClickEventListener(Tr, {CommandName: menuCommand, Text: itemText, IsDisabled: isDisabled, ImageUrl: Img ? Img.src : ''}) });
			WireUpEventHandler(Tr, 'mouseover', function(){ MouseOver(menuCommand,Tr, TdLeft, TdRight); });
	        WireUpEventHandler(Tr, 'mouseout', function(){ MouseOut(menuCommand,Tr, TdLeft, TdRight); });
	    }
		else
	    {
			WireUpEventHandler(Tr, 'click', function(){ return false; });
	        WireUpEventHandler(TdRight, 'selectstart', function(){ return false; });
	    }
	}	

	//Public method for displaying Menu.
	//this.Display = function(e)
	this.Display = function()
	{
	    MenuDiv.style.visibility = 'hidden';
	    MenuDiv.style.left = Left + 'px';    //this sets the position of the context menu as you click the options
        MenuDiv.style.top = 21 + 'px';     //top of menuitem
        MenuDiv.style.visibility = 'visible';
       
        return false;
	}	
	
	this.HideAll=function()
	{
	  Messenger_subMenu.Hide();
	  MenuDiv.style.visibility='hidden';
	  MenuTable.style.visibility='hidden';
	
	}
	
	
	//Public method to hide context Menu.
	this.Hide = function()
	{
		MenuDiv.style.visibility='hidden';
	
		
	}
	
	this.Hide2=function()
	{
	    //*****************
	   //alert(menu);
	   if(menu=="MyStatus")
	   {
	   MenuDiv.style.visibility='visible';
	   MenuTable.style.visibility='visible';
	
	   }
	   else
	   {
	   MenuDiv.style.visibility='hidden';
	   MenuTable.style.visibility='hidden';
	
	
       }
	}

   this.Show=function()
	{
	   MenuTable.style.visibility='visible';
	   MenuDiv.style.visibility='visible';
	 
    }
	
	this.GetTotalItems = function()
	{
	    return MenuTable.getElementsByTagName('tr').length;
	}
	
	
	//Public method Dispose.
	this.Dispose = function()
	{
	    while(EventHandlers.length > 0)
	        DetachEventHandler(EventHandlers.pop());
			
	    document.body.removeChild(MenuDiv);
	}
	
	//Mouseover event handler
	var MouseOver = function(menuCommand,Tr, TdLeft,TdRight)
	{	
	     menu=menuCommand;
	     TdLeft.style.backgroundColor = '#7db3ff';
	     TdLeft.style.borderTop = '1px solid white';    //the #666666 borders around image
	     TdLeft.style.borderBottom = '1px solid white';
	     TdLeft.style.borderLeft = '1px solid white';
	     TdLeft.style.fontFamily = 'Microsoft Sans Serif';
	     TdLeft.style.fontSize = 'XX-Small';
	  
	     TdRight.style.backgroundColor='#7db3ff';
	     TdRight.style.color = 'black'; 
	     TdRight.style.borderTop = '1px solid white';    //the #666666 borders around image
	     TdRight.style.borderBottom = '1px solid white';
		
	     if(menuCommand=="MyStatus")
	     {
	     Messenger_subMenu.Display();
	     }
	}
	
	//Mouseout event handler
	var MouseOut = function(menuCommand,Tr, TdLeft,TdRight)
	{	
	     TdLeft.style.backgroundColor = '#507cd1';
	     TdLeft.style.borderTop = '1px solid #507cd1';    //the #666666 borders around image
	     TdLeft.style.borderBottom = '1px solid #507cd1';
	     TdLeft.style.borderLeft = '1px solid #507cd1';
	     TdLeft.style.fontFamily = 'Microsoft Sans Serif';
	     TdLeft.style.fontSize = 'XX-Small';
		
	     TdRight.style.backgroundColor='#507cd1';
	     TdRight.style.borderTop = '1px solid #507cd1';    //the #666666 borders around image
	     TdRight.style.borderBottom = '1px solid #507cd1';
	  
	     TdRight.style.color = 'white'; 
	
	     if(menuCommand!="MyStatus")
	     Messenger_subMenu.Hide();
	     
	}
	
	//Private method to wire up event handlers.
	var WireUpEventHandler = function(Target, Event, Listener)
	{
	    //Register event.
	    if(Target.addEventListener)	   
			Target.addEventListener(Event, Listener, false);	    
	    else if(Target.attachEvent)	   
			Target.attachEvent('on' + Event, Listener);
	    else 
	    {
			Event = 'on' + Event;
			Target.Event = Listener;	 
		}
		
	    //Collect event information through object literal.
	    var EVENT = { Target: Target, Event: Event, Listener: Listener }
	    EventHandlers.push(EVENT);
	}
	
	//Private method to detach event handlers.
	var DetachEventHandler = function(EVENT)
	{
	    if(EVENT.Target.removeEventListener)	   
			EVENT.Target.removeEventListener(EVENT.Event, EVENT.Listener, false);	    
	    else if(EVENT.Target.detachEvent)	   
	        EVENT.Target.detachEvent('on' + EVENT.Event, EVENT.Listener);
	    else 
	    {		EVENT.Event = 'on' + EVENT.Event;
			EVENT.Target.EVENT.Event = null;	 
	    }
	}
	
	//Add Context Menu div on the document.

	document.body.appendChild(MenuDiv);

	//Register events.	
	
	WireUpEventHandler(Base, 'click', this.Hide2);  //********
	WireUpEventHandler(MenuDiv, 'click', function(){ return false; });
	WireUpEventHandler(MenuDiv, 'mouseout',this.Hide2);
	WireUpEventHandler(MenuDiv, 'mouseover', this.Show);
}

//event when options under My Status menu was clicked
var OnClick2 = function(Sender, EventArgs)
    {   
        switch(EventArgs.CommandName)
        {
            case 'Available':
                {
                
                  PageMethods.UpdatePresence("available");
                  break;
                }
            case 'Invisible':
                {
                  PageMethods.UpdatePresence("invisible");
                  break;
                }
            case 'Busy':
                {
                  PageMethods.UpdatePresence("busy");
                  break;
                }
            case 'Offline':
                {
                  PageMethods.UpdatePresence("unavailable");
                  break;
                }
               
           
        }
        
       
    }
    
 












































function SubMenu(Arguments)
    {
    //Global variables.
    //var Base:oBase;//Base: oBase,
            //Width: 120,                                        //sets the initial width of the context menu
            //FontColor: null,
            //HoverFontColor: null,
            //HoverBackgroundColor: null,
            //HoverBorderColor: null,
     
	var Base = Arguments.Base ? Arguments.Base : document.documentElement;
	var Width = 75;            //set the width of the context menu
   	var HoverFontColor = '#666666';
	var HoverBackgroundColor = '#666666';
	var HoverBorderColor ='orange';
	var ClickEventListener = Arguments.ClickEventListener ? Arguments.ClickEventListener : function(){ return false; };
	var SubMenuDiv = document.createElement('div');
    var SubMenuTable = document.createElement('table');
    var Index = 0;
    var EventHandlers = new Array();
	
	//Style Context Menu div.                 //the entire context menu
    SubMenuDiv.id = 'subMenu'; 
    SubMenuDiv.style.position = 'absolute';
    SubMenuDiv.style.backgroundColor = '#666666';  
    SubMenuDiv.style.border = '2px groove gray';  //1 px border thickenss orange background of context menu
    SubMenuDiv.style.verticalAlign = 'top';
    SubMenuDiv.style.textAlign = 'left';
	SubMenuDiv.style.visibility = 'hidden';
	SubMenuDiv.style.width = (Width + 11) + 'px';
	
	//Styles Context Menu table.
	SubMenuTable.id = 'MenuTable'; 
	SubMenuTable.style.width = (Width + 10) + 'px';
	SubMenuTable.border = 0;
	SubMenuTable.cellPadding = 0;
	SubMenuTable.cellSpacing = 0;
	
	//Append Context Menu table into Context Menu div.
	SubMenuDiv.appendChild(SubMenuTable);
	
	//Public method for adding Context Menu Items.
	this.AddItem = function(imgSrc,imgSize, itemText, isDisabled, commandName)
	{	    
		var Tr = SubMenuTable.insertRow(Index++);   //table row names
	    Tr.style.fontFamily = 'Microsoft Sans Serif';
	    Tr.style.fontSize = 'XX-Small';           //set Font size
	    Tr.style.fontWeight = 'normal';
	    Tr.style.backgroundColor = '#507cd1';
	    Tr.style.cursor = 'default';
	    
	    var TdLeft = Tr.insertCell(0);  //table row image
	    TdLeft.style.width = 50 + 'px';
	    TdLeft.style.height = 15 + 'px';
	    TdLeft.style.textAlign = 'left';
	    //TdLeft.style.verticalAlign = 'left';
	    TdLeft.style.fontStyle = isDisabled ? 'italic' : 'normal'; 
	    TdLeft.innerHTML = '&nbsp;&nbsp;&nbsp;'+itemText;        //? itemText : '&nbsp;';
	    TdLeft.style.color='white';
	
	    var TdRight = Tr.insertCell(1);     //text
	    TdRight.style.width = 30 + 'px';
	    TdRight.style.height = 10 + 'px';
	    TdRight.style.textAlign = 'center';
	    //TdRight.style.verticalAlign = 'left'; 
	 	
		if(imgSrc)
		{
	        var Img = new Image();	 
	        Img.id = 'Img';    
	        Img.src = imgSrc;
	        Img.style.width = imgSize + 'px';	 //set image width here
	        Img.style.height = imgSize + 'px';	 //set image height here
	        Img.disabled = isDisabled; 
			
	        TdRight.appendChild(Img);	
	    }
	    else
	        TdRight.innerHTML = '&nbsp;';
		
	    //Register events.	    
	    if(!isDisabled)
		{	        
			WireUpEventHandler(Tr, 'click', function(){ ClickEventListener(Tr, {CommandName: commandName, Text: itemText, IsDisabled: isDisabled, ImageUrl: Img ? Img.src : ''}) });
			WireUpEventHandler(Tr, 'mouseover', function(){ MouseOver(Tr, TdLeft, TdRight); });
	        WireUpEventHandler(Tr, 'mouseout', function(){ MouseOut(Tr, TdLeft, TdRight); });
	    }
		else
	    {
			WireUpEventHandler(Tr, 'click', function(){ return false; });
	        WireUpEventHandler(TdRight, 'selectstart', function(){ return false; });
	    }
	}	
	
	//Public method for displaying Context Menu.
	this.Display = function()
	{
	
	    
	    SubMenuDiv.style.visibility = 'hidden';
	    SubMenuDiv.style.left = Arguments.subleft + 'px';    //this sets the position of the context menu as you click the options
        SubMenuDiv.style.top = 25 + 'px';     //top of menuitem
        SubMenuDiv.style.visibility = 'visible';
        
        return false;
	}	
	

	//Public method to hide context Menu.
	this.Hide = function()
	{
		SubMenuDiv.style.visibility='hidden';
	}
	
	//Public method Dispose.
	this.Dispose = function()
	{
	    while(EventHandlers.length > 0)
	        DetachEventHandler(EventHandlers.pop());
			
	    document.body.removeChild(SubMenuDiv);
	}
	
	//Public method GetTotalItems.
	this.GetTotalItems = function()
	{
	    return SubMenuTable.getElementsByTagName('tr').length;
	}
	
	//Mouseover event handler
	var MouseOver = function(Tr, TdLeft,TdRight)
	{	
	     
	     document.getElementById('Messenger').style.visibility='visible';   
	     TdLeft.style.backgroundColor = '#7db3ff';
	     TdLeft.style.borderTop = '1px solid white';    //the #666666 borders around image
	     TdLeft.style.borderBottom = '1px solid white';
	     TdLeft.style.borderLeft = '1px solid white';
	  
	     TdRight.style.backgroundColor='#7db3ff';
	     TdRight.style.color = 'black'; 
	     TdRight.style.borderTop = '1px solid white';    //the #666666 borders around image
	     TdRight.style.borderBottom = '1px solid white';
	   
	     
	}
	
	//Mouseout event handler
	var MouseOut = function(Tr, TdLeft,TdRight)
	{	
	     document.getElementById('Messenger').style.visibility='visible';   
	     TdLeft.style.backgroundColor = '#507cd1';
	     TdLeft.style.borderTop = '1px solid #507cd1';    //the #666666 borders around image
	     TdLeft.style.borderBottom = '1px solid #507cd1';
	     TdLeft.style.borderLeft = '1px solid #507cd1';
		
	     TdRight.style.backgroundColor='#507cd1';
	     TdRight.style.borderTop = '1px solid #507cd1';    //the #666666 borders around image
	     TdRight.style.borderBottom = '1px solid #507cd1';
	  
	     TdRight.style.color = 'white'; 
	}
	
	//Private method to wire up event handlers.
	var WireUpEventHandler = function(Target, Event, Listener)
	{
	    //Register event.
	    if(Target.addEventListener)	   
			Target.addEventListener(Event, Listener, false);	    
	    else if(Target.attachEvent)	   
			Target.attachEvent('on' + Event, Listener);
	    else 
	    {
			Event = 'on' + Event;
			Target.Event = Listener;	 
		}
		
	    //Collect event information through object literal.
	    var EVENT = { Target: Target, Event: Event, Listener: Listener }
	    EventHandlers.push(EVENT);
	}
	
	//Private method to detach event handlers.
	var DetachEventHandler = function(EVENT)
	{
	    if(EVENT.Target.removeEventListener)	   
			EVENT.Target.removeEventListener(EVENT.Event, EVENT.Listener, false);	    
	    else if(EVENT.Target.detachEvent)	   
	        EVENT.Target.detachEvent('on' + EVENT.Event, EVENT.Listener);
	    else 
	    {
			EVENT.Event = 'on' + EVENT.Event;
			EVENT.Target.EVENT.Event = null;	 
	    }
	}
	
	//Add Context Menu div on the document.
	document.body.appendChild(SubMenuDiv);
	
	//Register events.	
	WireUpEventHandler(Base, 'click', this.Hide);
	WireUpEventHandler(SubMenuDiv, 'Menu', function(){ return false; });
}


